package com.victor.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.victor.entity.Administrator;
import com.victor.entity.Department;
import com.victor.entity.soncompany.Soncompany;

@Mapper
public interface SoncompanyDao {

	/**
	 * 添加子公司
	 * 
	 * @param soncompany
	 * @return
	 */
	int addSonCompany(Soncompany soncompany);

	/**
	 * 添加部门信息
	 * 
	 * @param departments
	 * @return
	 */
	@Insert({ "insert into department (d_name,buildtime,joincompany_id) values (#{d_name},NOW(),#{joincompany_id})" })
	int addSonCompanydepartments(Department departments);

	/**
	 * 查询公司本部员工
	 * 
	 * @param soncompanyid
	 * @return
	 */
	@Select({ "select * from administrator where join_son_company_id=#{soncompanyid}" })
	List<Administrator> getOwnEmployee(@Param("soncompanyid") String soncompanyid);

	/**
	 * 查询下属公司列表
	 * 
	 * @param soncompanyid
	 * @return
	 */
	@Select({ "select * from son_company where higher_company_id=#{soncompanyid}" })
	List<Soncompany> getSubordinateCompany(@Param("soncompanyid") String soncompanyid);

	/**
	 * 修改公司详情
	 * 
	 * @param soncompany
	 * @return
	 */
	int updSoncompany(Soncompany soncompany);

	/**
	 * 删除所有本公司的原部门
	 * 
	 * @param companyid
	 * @return
	 */
	@Delete({"delete from department where joincompany_id=#{companyid}"})
	int delFormerDepartment(@Param("companyid") Integer companyid);

}
